<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$data.id}"/>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>教练姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data.name}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="tel" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data.tel}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>教练头像
                </label>
                <div class="layui-upload-drag image" id="image" style="width: 168px;">
                    <i class="layui-icon" style="font-size: 40px;">&#xe67c;</i>
                    <p>点击上传</p>
                </div>
                <div style="position: relative;top:-120px;left:100px;">
                    <img src="{$data.coach_image}" alt="..." style="width: 300px;height: 175px;" />
                    <input type="hidden" name="coach_image" value="{$data.coach_image}" />
                    <a class="imgDel" data-type="1" data-src="{$data.coach_image}"> <i class="layui-icon layui-icon-close-fill" style="font-size: 20px;color: #0C0C0C;"></i> </a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>教练类型
                </label>
                <div class="layui-input-inline">
                    <select  name="driver_id">
                        {volist name="driver" id="v"}
                        <option {if condition="$data['driver_id'] eq $v['id']"}selected{/if} value="{$v.id}">{$v.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>请假日期
                </label>
                <div class="layui-input-inline">
                    <textarea name="qingjia" style="width:220px;height:200px;">{$data.qingjia}</textarea>
                    多个日期以&分开<br/>(格式：2019-11-12)
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','upload','layer'],function() {
        $ = layui.jquery;
        let form = layui.form,
            upload = layui.upload,
            layer = layui.layer;

        //上传
        upload.render({
            elem: '#image'
            ,url: '{:url("shopImage")}'
            ,done: function(res){
                if (res.code !== 1){
                    layer.msg(res.msg, {icon: 5,time:1000},function () {
                        return false;
                    });
                }
                let dome = '<div style="position: relative;top:-120px;left:100px;"><img src="'+ res.url +'" alt="..." style="width: 300px;height: 175px;">\n' +
                    '<input type="hidden" name="coach_image" value="'+ res.url +'">\n' +
                    '<a class="imgDel" data-type="1" data-src="'+ res.url +'">\n' +
                    '<i class="layui-icon layui-icon-close-fill" style="font-size: 20px;color: #0C0C0C;"></i>\n' +
                    '</a></div>';
                $('#image').after(dome);
                form.render();
            }
        });
        //删除图片
        $(document).on('click','.imgDel',function () {
            var that = $(this);
            $.post('{:url("goodsImgDel")}',{imgUrl:that.attr('data-src')},function (res) {
                if (res.code !== 1){
                    layer.msg(res.msg, {icon: 5,time:1000},function () {
                        return false;
                    });
                }else {
                        that.parent().remove();
                        form.render();
                    layer.msg(res.msg, {icon: 6,time:1000});
                }
            })
        });

        //监听提交
        form.on('submit(add)',function(data) {
            //发异步，把数据提交给php
            $.post('{:url("coach/coachEditForm")}', data.field, function (res) {
                console.log(res);
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000},function () {
                        xadmin.close();
                        xadmin.father_reload();
                    });
                }else {
                    layer.msg(res.msg, {icon: 5,time:1500});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
